package cn.livingCloud.dto;

import cn.livingCloud.entity.core.Dept;
import cn.livingCloud.utils.DateUtils;
import org.apache.commons.lang.StringUtils;

/**
 * Created by DingJie on 2016/5/26.
 */
public class DeptFormDto {
    private String uuid;
    private String name;
    private String parentUuid;
    private String createDateTime;
    private boolean archive;
    private DeptDto deptDto;

    public DeptFormDto() {
    }

    public DeptFormDto(Dept dept) {
        this.uuid = dept.getUuid();
        this.archive = dept.getArchive();
        this.name = dept.getName();
        this.parentUuid = dept.getParentUuid();
        this.createDateTime = DateUtils.toDateText(dept.getCreateDateTime()
                , DateUtils.DEFAULT_DATE_TIME_FORMAT);
    }

    public DeptFormDto(DeptDto deptDto) {
        this.deptDto = deptDto;
    }

    public DeptFormDto(Dept dept, DeptDto deptDto) {
        this.uuid = dept.getUuid();
        this.archive = dept.getArchive();
        this.name = dept.getName();
        this.parentUuid = dept.getParentUuid();
        this.createDateTime = DateUtils.toDateText(dept.getCreateDateTime()
                , DateUtils.DEFAULT_DATE_TIME_FORMAT);
        this.deptDto = deptDto;
    }

    public DeptFormDto(String parent_uuid) {
        this.parentUuid = parent_uuid;
    }

    public DeptDto getDeptDto() {
        return deptDto;
    }

    public void setDeptDto(DeptDto deptDto) {
        this.deptDto = deptDto;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getParentUuid() {
        return parentUuid;
    }

    public void setParentUuid(String parentUuid) {
        this.parentUuid = parentUuid;
    }

    public String getCreateDateTime() {
        return createDateTime;
    }

    public void setCreateDateTime(String createDateTime) {
        this.createDateTime = createDateTime;
    }

    public boolean isArchive() {
        return archive;
    }

    public void setArchive(boolean archive) {
        this.archive = archive;
    }


    public void update(Dept dept) {
        dept.setName(this.name);
        dept.setArchive(this.isArchive());
        if (StringUtils.isNotEmpty(this.parentUuid)) {
            dept.setParentUuid(this.parentUuid);
        }
        if (this.createDateTime != null) {
            dept.setCreateDateTime(DateUtils.getDate(this.createDateTime));
        }
    }

    public void load(Dept dept) {
        this.uuid = dept.getUuid();
        this.archive = dept.getArchive();
        this.name = dept.getName();
        this.parentUuid = dept.getParentUuid();
        this.createDateTime = DateUtils.toDateText(dept.getCreateDateTime()
                , DateUtils.DEFAULT_DATE_TIME_FORMAT);
    }
}
